/*
 *The code is written by NaLi, All rights is reserved.
 */
package edu.ecust.design.web.model;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

public class Page<T> implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 9184749336548686198L;
	private List<T> list = Collections.emptyList();// 当页要显示的对象集
	private int pageId;// 当前页面ID，从1开始(首页pageId为1)，1,2,3,4,....
	private int pageSize = 1;// 每个页面的对象数
	private int maxPageId;// 末页ID
	private int totalCount;// 结果总数

	public Page() {

	}

	/**
	 * 使用limit的构造函数
	 * 
	 * @param list
	 *            结果列表
	 * @param limit
	 *            分页参数
	 * @param totalCount
	 *            总数
	 */
	public Page(List<T> list, Limit limit, int totalCount) {
		this(list, limit.getCurrentPageIndex(), limit.getPageSize(), totalCount);
	}

	public Page(List<T> list, int pageId, int pageSize, int totalCount) {
		this.list = list;
		this.pageId = pageId;
		this.pageSize = pageSize;
		this.totalCount = totalCount;

		int max = totalCount / pageSize;
		if (totalCount % pageSize != 0) {
			max = max + 1;
		} else {
			if (totalCount == 0)
				max = 1;
		}
		this.maxPageId = max;
	}

	public Page(List<T> list, int pageId, int pageSize, int maxPageId,
			int totalCount) {
		this.list = list;
		this.pageId = pageId;
		this.pageSize = pageSize;
		this.totalCount = totalCount;
		this.maxPageId = maxPageId;
	}

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	public List<T> getList() {
		return list;
	}

	public void setList(List<T> list) {
		this.list = list;
	}

	public int getPageId() {
		return pageId;
	}

	public void setPageId(int pageId) {
		this.pageId = pageId;
	}

	public int getMaxPageId() {
		return maxPageId;
	}

	public void setMaxPageId(int maxPageId) {
		this.maxPageId = maxPageId;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
}
